import api from "../utils/api";
import Utils from "../utils";
import {Toast} from 'antd-mobile-rn';

export default {


    /**
     * 登录
     */
    login:(form,success) => {
 
        Toast.loading("登陆中...",0);
        api({
            url: "/login",
            method: "POST",
            body: form
        }).then(data=>{
           
            //登录成功
            if(!data.success){
               Toast.info(data.msg);
               return;
            }
           
            Utils.setStorage("LoginUserInfo",data.result).then(()=>{
                Toast.hide();
                success(data.result);
            })
          
        
        }).catch(data=>{
            console.log("err::",data);
            Toast.info("登录失败,请重试...",1.5);
        })

    },
    /**
     * 发送验证码
     */
    sendCode:(param,success,error)=>{
        Toast.loading("发送中...",0);
        api({
            url:`/login/code/phone?phone=${param.phone}&serviceType=${param.serviceType}`,
            method:"GET"
        }).then(data=>{
            if(!data.success){
                Toast.info(data.msg);
                error();
                return;
            }
            Toast.hide();
            success();
        }).catch(()=>{
            Toast.info("发送失败请重试...");
            error();
        });

    },
    /**
     * 绑定手机
     */
    bindPhone:(form,success)=>{
        Toast.loading("绑定中...",0);
        api({
            url:"/login/bind/phone",
            method:"POST",
            body:form
        }).then(data=>{
            //登录成功
            if(!data.success){
                Toast.info(data.msg);
                return;
            }
            Toast.hide();
            success();
        }).catch(()=>{
            Toast.info("绑定失败请重试...");
        });
    }

}